home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / PROGWOB / PWOEVREC.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-26  |  3.0 KB  |  94 lines

  1. VERSION 5.00
  2. Begin VB.Form frmReceiver 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Message received by handling Broadcast event"
  5.    ClientHeight    =   690
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   6420
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   690
  13.    ScaleWidth      =   6420
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.CheckBox chkReceive 
  16.       Caption         =   "&Receive messages"
  17.       Height          =   255
  18.       Left            =   3480
  19.       TabIndex        =   2
  20.       Top             =   360
  21.       Width           =   2895
  22.    End
  23.    Begin VB.CheckBox chkGarble 
  24.       Caption         =   "&Garble messages"
  25.       Height          =   255
  26.       Left            =   120
  27.       TabIndex        =   1
  28.       Top             =   360
  29.       Width           =   2895
  30.    End
  31.    Begin VB.Label lblMessage 
  32.       Height          =   255
  33.       Left            =   120
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   6135
  37.    End
  38. Attribute VB_Name = "frmReceiver"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Option Explicit
  44. ' The Source variable is declared using
  45. '   the WithEvents keyword, so that the
  46. '   events of the frmEvents object
  47. '   assigned to it can be handled (see the
  48. '   Source_Broadcast event procedure).  When
  49. '   the reference is assigned, Visual Basic
  50. '   connects the object with the event
  51. '   procedure.
  52. Private WithEvents Source As frmEvents
  53. Attribute Source.VB_VarHelpID = -1
  54. Private Sub chkReceive_Click()
  55.     If chkReceive = vbChecked Then
  56.         Set Source = frmEvents
  57.     Else
  58.         ' Setting the WithEvents variable
  59.         '   to Nothing disconnects the
  60.         '   event procedure from the
  61.         '   frmEvents object.
  62.         Set Source = Nothing
  63.     End If
  64. End Sub
  65. Private Sub Form_Load()
  66.     chkReceive = vbChecked
  67. End Sub
  68. Private Sub Form_Unload(Cancel As Integer)
  69.     Set Source = Nothing
  70. End Sub
  71. ' Event procedure for the Broadcast event.
  72. '   Because the Message argument is ByRef,
  73. '   it can be altered -- and these changes
  74. '   will be seen by all subsequent
  75. '   handlers of the event.
  76. Private Sub Source_Broadcast(Message As String)
  77.     Dim intCt As Integer
  78.     lblMessage = Message
  79.     '
  80.     ' If Garble is checked, garble the
  81.     '   message.
  82.     If chkGarble = vbChecked Then
  83.         ' Use a random Step that hits every
  84.         '   third character (minimum) to
  85.         '   every ninth (maximum).
  86.         For intCt = 1 To Len(Message) Step (Int(7 * Rnd) + 3)
  87.             ' For characters that are to be garbled,
  88.             '   change the ASCII value by a random
  89.             '   amount from -3 to +3.
  90.             Mid$(Message, intCt, 1) = Chr$(Asc(Mid$(Message, intCt, 1)) + Int(7 * Rnd) - 3)
  91.         Next
  92.     End If
  93. End Sub
  94.